<!--
 * @Author: your name
 * @Date: 2020-11-16 15:50:13
 * @LastEditTime: 2020-11-27 15:45:13
 * @LastEditors: Please set LastEditors
 * @Description: 
    采购入库、产成品入库等 底部公用组件
    销售出库、基建出库等   底部公用组件




 * @FilePath: \cang-chu-guan-li-xi-tong\src\components\common\footerCommonBar.vue
-->

<template>
  <div style="margin-top: 20px">
    <!-- 单据 -->
    <a-form-model ref="ruleForm" :model="Form" v-bind="layout" :rules="rules"
      ><!-- 顶部的信息 -->
      <a-row>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item
            label="审核人"
            ref="responsible_person"
            prop="responsible_person"
          >
            <a-select
              v-model="Form.responsible_person"
              style="width: 100%"
              showSearch
              @change="setResponsible_person"
            >
              <a-select-option
                v-for="item in responsiblePersonList"
                :key="item.userId"
                :value="item.userName"
              >
                {{ item.workNo }} {{ item.userName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="检验人" ref="inspector" prop="inspector">
            <a-select
              v-model="Form.inspector"
              showSearch
              @change="setInspector"
              style="width: 100%"
            >
              <a-select-option
                v-for="item in inspectorList"
                :key="item.userId"
                :value="item.userName"
              >
                {{ item.workNo }} {{ item.userName }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="制单人" ref="" prop="">
            <!-- <a-select
              v-model="Form.single_producer"
              showSearch
              style="width: 100%"
              @change="setSingleProducer"
            >
              <a-select-option
                v-for="item in singleProducerList"
                :key="item.userId"
                :value="item.userName"
              >
                {{ item.workNo }} {{ item.userName }}
              </a-select-option>
            </a-select> -->
          </a-form-model-item>
        </a-col>

        <a-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24">
          <a-form-model-item label="检验日期" ref="" prop="">
            <a-date-picker
              v-model="Form.balanceDate"
              type="date"
              placeholder="请选择时间"
              style="width: 100%"
              @change="onChange"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>

    <!-- 提交按钮组  -->
    <div style="margin-top: 20px">
      <center>
        <a-button type="primary" style="margin-right: 20px"> 打印 </a-button>
        <a-button @click="Reset" style="margin-right: 20px">
          保存
        </a-button>
        <a-button type="primary" @click="Submit" style="margin-right: 20px">
          提交
        </a-button>
      </center>
    </div>
  </div>
</template>

<script>
import { CommonAjax } from "@/services/modules/common";
const comHttp = new CommonAjax(); // 公用接口

const rules = {};

export default {
  data() {
    return {
      Form: {
        responsible_person: "",
        responsible_person_Id: "",
        inspector: "",
        inspector_Id: "",
        single_producer: "",
        single_producer_Id: "",
        balanceDate: null,
      },
      // 格式
      layout: {
        labelCol: { span: 8 },
        wrapperCol: { span: 15 },
      },
      rules, // 规则
      responsiblePersonList: [], // 负责人列表
      inspectorList: [], // 检验人列表
      singleProducerList: [], //制单人列表
    };
  },
  mounted() {
    this.getResponsiblePersonList();
    this.getSingleProducerList();
    this.getInspectorList();
  },
  methods: {
    // 获取负责人
    getResponsiblePersonList() {
      const roleName = "仓库负责人员";
      let queryPath = "?roleName=" + roleName;
      comHttp.getUserRoleNameByUserNameId(queryPath).then((res) => {
        console.log(res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            userName: res.result[i].userName,
            userId: res.result[i].userId,
            workNo: res.result[i].workNo,
          };
          this.responsiblePersonList.push(data);
        }
        //   console.log("仓库负责人:::", this.responsiblePersonList);
      });
    },
    setResponsible_person(value, options) {
      this.Form.responsible_person_Id = options.key;
    },
    // 获取检验人
    getInspectorList() {
      const roleName = "仓库检验人员";
      let queryPath = "?roleName=" + roleName;
      comHttp.getUserRoleNameByUserNameId(queryPath).then((res) => {
        // console.log(res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            userName: res.result[i].userName,
            userId: res.result[i].userId,
            workNo: res.result[i].workNo,
          };
          this.inspectorList.push(data);
        }
        //   console.log("仓库检验人:::", this.inspectorList);
      });
    },
    setInspector(value, options) {
      this.Form.inspector_Id = options.key;
    },

    // 获取制单人
    getSingleProducerList() {
      const roleName = "仓库制单人员";
      let queryPath = "?roleName=" + roleName;
      comHttp.getUserRoleNameByUserNameId(queryPath).then((res) => {
        // console.log(res);
        for (let i = 0; i < res.result.length; i++) {
          let data = {
            userName: res.result[i].userName,
            userId: res.result[i].userId,
            workNo: res.result[i].workNo,
          };
          this.singleProducerList.push(data);
        }
        //   console.log("仓库制单人:::", this.singleProducerList);
      });
    },
    setSingleProducer(value, options) {
      this.Form.single_producer_Id = options.key;
    },
    // 单据日期函数
    onChange(date, dateString) {
      // console.log(date, dateString);
      this.Form.balanceDate = dateString;
    },

    // 提交函数
    Submit() {
      // console.log(this.Form);
      //  this.$emit()
      // 要提交的底部数据

      this.$emit("footer-data", this.Form);
    },

    // 重置函数
    Reset() {
      this.Form = {
        responsible_person: "",
        inspector: "",
        single_producer: "",
        balanceDate: null,
      };
      this.$emit("reset-data");
    },
  },
};
</script>

<style></style>
